/**
 * 设置光源 ShadowMap 尺寸, 适用于能够投射阴影的光源类型.
 * 
 * @argument pShadowSize 阴影投射范围尺寸.
 * @component LightComponent
 */
export default {
  start: function (self, ctx) {
    this.doShadowUpdate(self, ctx);
  },
  onParameterUpdate: function (self, ctx, key, value) {
    if (key === 'pShadowSize') {
      this.doShadowUpdate(self, ctx);
    }
  },
  doShadowUpdate: function (self, ctx) {
    // 组件检测, 如果不存在 LightComponent, 跳过处理.
    if (!self.hasComponent('LightComponent')) {
      return;
    }

    // Shadow Size: 阴影投影范围
    const SHADOW_SIZE = parseInt(self.getParameter('pShadowSize')) || 128;

    // Map Size: 阴影贴图尺寸, 根据所需清晰度与渲染性能, 可选 1024/2048/4096
    const MAP_SIZE = 1024;

    // 更新光照及阴影参数
    const light = self.getComponent('LightComponent').light;
    light.shadow.mapSize.set(MAP_SIZE, MAP_SIZE);
    light.shadow.camera.top = SHADOW_SIZE;
    light.shadow.camera.bottom = -SHADOW_SIZE;
    light.shadow.camera.left = -SHADOW_SIZE;
    light.shadow.camera.right = SHADOW_SIZE;
  }
}